<?php
function echoSequenceRow(& $team, & $teamStats, $row) {

    echo getEchoTR($row, "center");
    echo "  <td>" . getEchoValue($team->coach->getName()) . "</td>\n";
    echo "  <td>" . $team->getRosterLink() . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->wins) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->noLoss) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->noWin) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->loss) . "</td>\n";
    echo "</tr>\n";
}

function echoTempSequenceRow(& $team, & $teamStats, $row) {

    echo getEchoTR($row, "center");
    echo "  <td>" . getEchoValue($team->coach->getName()) . "</td>\n";
    echo "  <td>" . $team->getRosterLink() . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->currentWins) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->currentNoLoss) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->currentNoWin) . "</td>\n";
    echo "  <td>" . getEchoValue($teamStats->currentLoss) . "</td>\n";
    echo "</tr>\n";
}

$showStats = true;
include_once ("includes/header.php");

$sort = $_GET["sort"];
switch ($sort) {
    case 2 :
        uasort($teams->teams, "noLossesSort");
        break;
    case 3 :
        uasort($teams->teams, "noWinsSort");
        break;
    case 4 :
        uasort($teams->teams, "lossesSort");
        break;
    case 5 :
        uasort($teams->teams, "tempWinsSort");
        break;
    case 6 :
        uasort($teams->teams, "tempNoLossesSort");
        break;
    case 7 :
        uasort($teams->teams, "tempNoWinsSort");
        break;
    case 8 :
        uasort($teams->teams, "tempLossesSort");
        break;
    case 1 :
    default :
        uasort($teams->teams, "winsSort");
        break;
}

echo<<< EOQ
            <caption><h1>Team Sequences</h1></caption>
            <tr align="center">
              <th colspan="6">All Time</th>
            </tr>\n
            <tr align="center">
              <th>Coach</th>
              <th>Team</th>
              <th><a href="./sequences.php?sort=1">Wins</a></th>
              <th><a href="./sequences.php?sort=2">Without Losing</a></th>
              <th><a href="./sequences.php?sort=3">Without Winning</a></th>
              <th><a href="./sequences.php?sort=4">Losses</a></th>
            </tr>\n
EOQ;

$i = 0;
foreach ($teams->teams as $team) {
    echoSequenceRow($team, $team->getStats(), ++ $i);
}
echo<<< EOQ
            <tr align="center">
              <th colspan="6"><br><br>Current Form</th>
            </tr>\n
            <tr align="center">
              <th>Coach</th>
              <th>Team</th>
              <th><a href="./sequences.php?sort=5">Wins</a></th>
              <th><a href="./sequences.php?sort=6">Without Losing</a></th>
              <th><a href="./sequences.php?sort=7">Without Winning</a></th>
              <th><a href="./sequences.php?sort=8">Losses</a></th>
            </tr>\n
EOQ;

$i = 0;
foreach ($teams->teams as $team) {
    echoTempSequenceRow($team, $team->getStats(), ++ $i);
}
include ("includes/footer.php");
?>
